Skip to content

Write a class holding a property as one class - #151

Merged
HackTuah merged 1 commit into
mainfrom
property-class
Dec 6, 2026
Merged

HackTuah merged 1 commit into
mainfrom
property-class

Conversation

@HackTuah

@HackTuah HackTuah commented Dec 6, 2026

Copy link
Copy Markdown
Member

What

Under the default (ECMA-262) reading, the translator wrote a character class holding a property, and a property on its own, as a group: ^\p{L}*$ became ^(?:\p{L})*$, and ^[\p{L}\d]*$ became ^(?:[\x{30}-\x{39}]|\p{L})*$. A repeated group keeps a frame for each repetition, so these patterns refused a long string ("could not be matched against the required pattern in the memory a check may hold"):

pattern 40,000 letters 100,000 letters under :pcre
^\p{L}*$ served refused served
^[\p{L}\d]*$ served refused served
^[a-z0-9]*$ served served served

1.0.2 serves all of them at any length the body allows, and the docs say a class repeated is served at any length.

Such a class is now written as one class of the library's, with \p{...} inside it, negated where the class is: ^[\p{L}]*$, ^[\x{30}-\x{39}\p{L}]*$, ^[^\p{N}]*$. In UTF mode the subject holds no surrogate, so a negated class is ECMA-262's complement.

Proof

  • A planted test: six patterns, a negated class with ranges among them, against strings up to 200,000 characters. It fails on the old writing-out and passes on the new.
  • The same answers, rerun on OTP 28.5.0.9 and 29.1 against node 22's recorded answers:
    • the differential: 300,000 generated pairs, 4,400 corpus pairs and 299 construct pairs, with 0 disagreements and 0 compile disagreements;
    • the grammar's edge cases: answers identical to the previous build;
    • 1,755 property forms: the same membership as before.
  • The uncharged canary passes on both runtimes.

Checks

tools/gate.sh passes on this tree. The suite passes on Elixir 1.20 with OTP 29.

Under the default reading a character class holding a property, and a
property on its own, were written out as a group: \p{L}* became
(?:\p{L})*. A repeated group keeps a frame for each repetition, so
^\p{L}*$ refused a string of 100,000 letters ("the memory a check may
hold"), where 1.0.2 and pattern_dialect: :pcre serve it.

Such a class is now one class of the library's, with \p{...} inside it,
negated where the class is: [\x{30}-\x{39}\p{L}], [^\p{N}]. It matches
the same code points, and repeated it holds no frame per repetition.
The differential against node, the property comparison and the
uncharged canary give the same answers as before on OTP 28 and 29.

Signed-off-by: Ayla Croft <ayla@scriptkittyos.com>
@HackTuah
HackTuah merged commit 3f7c04e into main Dec 6, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant